import struct

if __name__ == '__main__':
    dataset = 'wbCt100Sep08'
    #dataset = 'th-test'
    filename = ('webgraph','transposegraph')[0]
    wg1 = open(dataset+'/'+filename+'.bin','rb').read()
    wg2 = open(dataset+'/'+filename+'.bin','rb')
    wgindex1 = {}
    wgindex2 = {}

    totalnode = 0 
    intsize = 4
    t = 0
    #read webgraph
    pos = 0
    while 1:
        try:
            src = struct.unpack_from('i',wg1,pos)[0]
            pos += 4
            
            outdegree = struct.unpack_from('i',wg1,pos)[0]
            wgindex1[int(src)] = int(outdegree)
            t += 1
            pos += 4*(outdegree+1)
        except:
            break
    
    while 1:
        data = wg2.read(intsize)
        if data == '':
            break
        src = struct.unpack('i',data)[0]

        

        data = wg2.read(intsize)
        if data == '':
            break
        outdegree = struct.unpack('i',data)[0]

        wgindex2[int(src)] = int(outdegree)
        totalnode += 1
        for i in range(outdegree):
            data = wg2.read(intsize)
            if data == '':
                break
            dest = struct.unpack('i',data)[0]
    wg2.close()

    print 'totalnode = ',totalnode
    print len(wgindex1.keys())
    print len(wgindex2.keys())
    print t
    print wgindex1 == wgindex2
